//
//  ImageListParse.m
//  LocalTravel
//
//  Created by zheng ji on 14-3-17.
//  Copyright (c) 2014年 jxw. All rights reserved.
//

#import "ImageListParse.h"
@interface ImageListParse ()
{
    NSMutableDictionary* _sceneryDict;
    NSMutableArray* _imageList;
    NSString* _currentElementName;
}
@end
@implementation ImageListParse
-(ImageListParse*)initWithXmlData:(NSString*)xmlData{
    NSXMLParser* parser=[[NSXMLParser alloc] initWithData:[xmlData dataUsingEncoding:NSUTF8StringEncoding]];
    parser.delegate=self;
    parser.shouldProcessNamespaces=NO;
    [parser parse];
    
    
    return  self;
}

-(void)parserDidStartDocument:(NSXMLParser *)parser{
    _sceneryDict=[[NSMutableDictionary alloc]init];
    _imageList=[[NSMutableArray alloc]init];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    _currentElementName=elementName;
    
    
    
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)value{
    if([_currentElementName isEqualToString:@"imagePath"]){
        [_imageList addObject:value];
       
    }
    if([_currentElementName isEqualToString:@"imageBaseUrl"]){
        
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"sizeCode"]){
        
        [_sceneryDict setObject:value forKey:_currentElementName];
    }
    
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
    [_sceneryDict setObject:_imageList forKey:@"imageList"];
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
    
}


-(NSDictionary*) getScenaryImage{
    return _sceneryDict;
}
@end
